import com.zlf.dao.AdminMapper;
import com.zlf.dao.AuthMapper;
import com.zlf.dao.MenuMapper;
import com.zlf.dao.RoleMapper;
import com.zlf.entity.Admin;
import com.zlf.entity.Role;
import com.zlf.service.api.AdminService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author ：张利锋
 * @date ：Created in 2020/11/7 19:46
 * @description： TOOD
 * @version: 1.0
 */
//指定junit运行容器
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring-persist-mybatis.xml", "classpath:spring-persist-tx.xml"})
public class test {
    @Autowired
    private DataSource dataSource;
    @Autowired
    private AdminMapper adminMapper;
    @Autowired
    private AdminService adminService;
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private AuthMapper authMapper;
    @Autowired
    BCryptPasswordEncoder passwordEncoder;

    @Test
    public void add1() {
        Admin admin = new Admin(null, "zlf", "123", "二狗", "qwe@qq.com", "2020-10-10");
        adminService.saveAdmin(admin);
    }

    @Test
    public void meuu(){

    }


    @Test
    public void add() {
        for (int i = 1; i <=500 ; i++) {
            String b="后羿"+i+"号";
            Role role = new Role(null,b);
            roleMapper.insert(role);
        }


    }

    @Test
    public void logtest() {
        //尽量用log打印，systemout是一种io，耗资源
        Log log = LogFactory.getLog(test.class);
        log.error("6666666666666666666666666666666666666");
        log.info("222");
        adminService.findAll().forEach(System.out::println);
    }

    @Test
    public void testdatasource() {
        try {
            Connection connection = dataSource.getConnection();
            System.out.println(connection);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void testt() {



    }

}
